<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:jdbc="http://www.springframework.org/schema/jdbc"
	xmlns:security="http://www.springframework.org/schema/security"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
	xmlns:tx="http://www.springframework.org/schema/tx" xmlns:util="http://www.springframework.org/schema/util"
	xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p"
	xmlns:cache="http://www.springframework.org/schema/cache" xmlns:jaxws="http://cxf.apache.org/jaxws"
	xmlns:jaxrs="http://cxf.apache.org/jaxrs"
	xmlns:task="http://www.springframework.org/schema/task"
	xmlns:ehcache="http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring"
	xmlns:core="http://cxf.apache.org/core" xmlns:oxm="http://www.springframework.org/schema/oxm"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
			http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.1.xsd
			http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.1.xsd
			http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
			http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.1.xsd
			http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
			http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
			http://www.springframework.org/schema/cache  http://www.springframework.org/schema/cache/spring-cache.xsd
			http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring/ehcache-spring-1.2.xsd
			http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.1.xsd
			http://www.springframework.org/schema/oxm http://www.springframework.org/schema/oxm/spring-oxm-3.0.xsd
			http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd
			http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd
			http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd
			http://cxf.apache.org/configuration/security http://cxf.apache.org/schemas/configuration/security.xsd">

	<!-- Root Context: defines shared resources visible to all other web components -->
	<context:annotation-config />
	<context:component-scan base-package="com.truyen.persistence*" />
	<context:component-scan base-package="com.truyen.service*" />
	<context:component-scan base-package="com.truyen.utils" />
	<context:component-scan base-package="com.truyen.aspect*" />
	<context:component-scan base-package="com.truyen.social" />

	<!-- Enable annotation to access to properties file in properties/methods -->
	<context:property-placeholder
		properties-ref="appProperties" />
	<util:properties id="appProperties"
		location="/WEB-INF/spring/appServlet/config.properties" />
		
	<!-- ADD PERSISTENCE SUPPORT HERE (jpa, hibernate, etc) -->
	<tx:annotation-driven transaction-manager="transactionManager" />
	<tx:annotation-driven transaction-manager="transactionManager1" />
	<bean
		class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />

	<bean id="truyenOnlineEmf"
		class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean">
		<property name="persistenceUnitName" value="truyenOnline" />
	</bean>

	<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"
		p:entityManagerFactory-ref="truyenOnlineEmf" />
		
	<bean id="transactionManager1" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
		<property name="dataSource" ref="dataSource" />
	</bean>
	
	<!-- Shared JDBC Data Access Template -->
	<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
		<constructor-arg ref="dataSource" />
	</bean>

	<!-- Embedded database for storing connections -->
	<jdbc:embedded-database id="dataSource" type="H2">
		<jdbc:script location="classpath:/org/springframework/social/connect/jdbc/JdbcUsersConnectionRepository.sql" />
	</jdbc:embedded-database>

	<!-- AspectJ beans -->
	<aop:aspectj-autoproxy />
	<bean id="userAspect" class="com.truyen.aspect.UserAspect"
		factory-method="aspectOf" p:userDetailService-ref="userDetailService" />

	<!-- spring security configuration -->
	<security:global-method-security
		pre-post-annotations="enabled" />
	<security:http pattern="/dang-nhap.htm" security="none" />
	<security:http pattern="**/resources/**" security="none" />
	<security:http auto-config="true" use-expressions="true"
		access-denied-page="/thanh-vien/dang-ky.htm">
		<security:intercept-url pattern="/**" access="permitAll" />
		<security:session-management>
			<security:concurrency-control
				max-sessions="10" error-if-maximum-exceeded="false" />
		</security:session-management>

		<security:form-login login-page="/dang-nhap.htm"
			login-processing-url="/j_spring_security_check"
			authentication-failure-url="/dang-nhap.htm?error=true"
			default-target-url="/truyen-tranh/trang-chu.htm" always-use-default-target="true" />

		<security:logout logout-url="/j_spring_security_logout"
			logout-success-url="/truyen-tranh/trang-chu.htm" />
	</security:http>
	<bean id="userDetailService" class="com.truyen.service.impl.UserDetailServiceImpl" />
	<bean id="md5PasswordEncoder"
		class="org.springframework.security.authentication.encoding.Md5PasswordEncoder" />
	<security:authentication-manager alias="springAuthManager">
		<security:authentication-provider
			user-service-ref="userDetailService">
			<security:password-encoder ref="md5PasswordEncoder" />
		</security:authentication-provider>
	</security:authentication-manager>

	<!-- Mail Sender -->
	<bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
		<property name="host" value="smtp.gmail.com" />
		<property name="port" value="587" />
		<property name="username" value="admin@truyenz.com" />
		<property name="password" value="!@#$thugianmotti!@#$" />

		<property name="javaMailProperties">
			<props>
				<prop key="mail.smtp.auth">true</prop>
				<prop key="mail.smtp.starttls.enable">true</prop>
			</props>
		</property>
	</bean>

	<bean id="mailMail" class="com.truyen.utils.MailMail">
		<property name="mailSender" ref="mailSender" />
	</bean>

	<!-- cache -->
<!-- 	<cache:annotation-driven /> -->
	<ehcache:annotation-driven cache-manager="cacheManager" />
	<bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">   
         <property name="configLocation" value="/WEB-INF/ehcache.xml" />    
    </bean>
     <bean id="chapterTmpTruyenTranhService" class="com.truyen.service.impl.ChapterTmpTruyenTranhServiceImpl" />
     <bean id="chapterTruyenTranhService" class="com.truyen.service.impl.ChapterTruyenTranhServiceImpl" />
     <bean id="truyenTranhService" class="com.truyen.service.impl.TruyenTranhServiceImpl" />
     
     <bean id="chapterTmpTruyenKiemHiepService" class="com.truyen.service.impl.ChapterTmpTruyenKiemHiepServiceImpl" />
     <bean id="chapterTruyenKiemHiepService" class="com.truyen.service.impl.ChapterTruyenKiemHiepServiceImpl" />
     <bean id="truyenKiemHiepService" class="com.truyen.service.impl.TruyenKiemHiepServiceImpl" />
     
     <bean id="chapterTmpTruyenTrinhThamService" class="com.truyen.service.impl.ChapterTmpTruyenTrinhThamServiceImpl" />
     <bean id="chapterTruyenTrinhThamService" class="com.truyen.service.impl.ChapterTruyenTrinhThamServiceImpl" />
     <bean id="truyenTrinhThamService" class="com.truyen.service.impl.TruyenTrinhThamServiceImpl" />
     
     <bean id="chapterTmpTruyenTinhCamService" class="com.truyen.service.impl.ChapterTmpTruyenTinhCamServiceImpl" />
     <bean id="chapterTruyenTinhCamService" class="com.truyen.service.impl.ChapterTruyenTinhCamServiceImpl" />
     <bean id="truyenTinhCamService" class="com.truyen.service.impl.TruyenTinhCamServiceImpl" />
     
     <bean id="chapterTmpTruyenMaService" class="com.truyen.service.impl.ChapterTmpTruyenMaServiceImpl" />
     <bean id="chapterTruyenMaService" class="com.truyen.service.impl.ChapterTruyenMaServiceImpl" />
     <bean id="truyenMaService" class="com.truyen.service.impl.TruyenMaServiceImpl" />
     
     <bean id="chapterTamService" class="com.truyen.service.impl.ChapterTamServiceImpl" />
     
     <bean id="anhDepService" class="com.truyen.service.impl.AnhDepServiceImpl" />
     
    

	<bean id="axiomMessageFactory"
		class="org.springframework.ws.soap.axiom.AxiomSoapMessageFactory">
		<property name="payloadCaching" value="true" />
	</bean>
	
	<!-- Task scheduler configuration -->
	<task:annotation-driven executor="gateExecutor"
		scheduler="gateScheduler" />
	<task:executor id="gateExecutor" pool-size="5" />
	<task:scheduler id="gateScheduler" pool-size="10" />
	
</beans>
